package com.cqu.lpss.controller;

import com.cqu.lpss.pojo.PageBean;
import com.cqu.lpss.pojo.Result;
import com.cqu.lpss.pojo.Scoringcriterions;
import com.cqu.lpss.service.impl.ScoringCriterionsImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/scoringcriterion")
public class ScoringCriterionsController {
    @Autowired
    ScoringCriterionsImpl scoringCriterionsImpl;
    @PostMapping("/findByClass")
    public Result findByClass(@RequestParam Integer classId){
        List<Scoringcriterions> ans = scoringCriterionsImpl.findByClass(classId);
        if(ans==null){
            return Result.erro("出现错误");
        }else {
            return  Result.success(ans);
        }
    }
    @PostMapping
    public Result list(@RequestParam(defaultValue = "1")int page,
                       @RequestParam(defaultValue = "10")int pageSize,
                       Integer classId,
                       String scName){
        PageBean<Scoringcriterions> pageBean = scoringCriterionsImpl.list(page, pageSize, classId, scName);
        return Result.success(pageBean);
    }
    @PostMapping("/add")
    public Result add(@RequestBody Scoringcriterions scoringcriterion){
        int ans = scoringCriterionsImpl.add(scoringcriterion);
        if(ans==1){
            return Result.success();
        }else {
            return Result.erro("InsertErro");
        }
    }
    @PostMapping("/edit")
    public Result edit(@RequestBody Scoringcriterions scoringcriterion){
        int ans = scoringCriterionsImpl.edit(scoringcriterion);
        if(ans==1){
            return Result.success();
        }else {
            return Result.erro("EditErro");
        }
    }
}
